package com.infocollect.project.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.infocollect.project.api.entity.TappMenuEntity;
import com.infocollect.project.api.mapper.TappMenuMapper;
import com.infocollect.project.api.req.UserPowerMenuReq;
import com.infocollect.project.api.service.ITappMenuService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (TappMenu)表服务实现类
 *
 * @author makejava
 * @since 2019-12-25 10:32:29
 */
@Service("tappMenuService")
public class TappMenuServiceImpl extends ServiceImpl<TappMenuMapper, TappMenuEntity> implements ITappMenuService {


    /**
     * 通过ID查询单条数据
     *
     * @param fid 主键
     * @return 实例对象
     */
    @Override
    public TappMenuEntity queryById(Long fid) {
        return this.baseMapper.selectById(fid);
    }


    /**
     * 查询多条数据
     *
     * @return 对象列表
     * @menu 根据实体对象是否有值 进行查询
     */
    @Override
    public List<TappMenuEntity> queryAll(TappMenuEntity menu) {
        return this.baseMapper.queryAll(menu);
    }

    /**
     * 新增数据
     *
     * @param tappMenu 实例对象
     * @return 实例对象
     */
    @Override
    public TappMenuEntity insert(TappMenuEntity tappMenu) {
        this.baseMapper.insert(tappMenu);
        return tappMenu;
    }

    /**
     * 修改数据
     *
     * @param tappMenu 实例对象
     * @return 实例对象
     */
    @Override
    public TappMenuEntity update(TappMenuEntity tappMenu) {
        this.baseMapper.updateById(tappMenu);
        return this.queryById(tappMenu.getFid());
    }

    /**
     * 通过主键删除数据
     *
     * @param fid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long fid) {
        return this.baseMapper.deleteById(fid) > 0;
    }

    /**
     * 根据用户的名称，机构编码 部门编码 获取用户拥有的权限菜单
     *
     * @return 对象列表
     * @userparam
     */
    @Override
    public List<TappMenuEntity> QueryUserPowerMenu(UserPowerMenuReq userparam) {
        return this.baseMapper.QueryUserPowerMenu(userparam);
    }

    /**
     * @param menuUrl
     * @return
     */
    @Override
    public TappMenuEntity queryByMenuUrl(String menuUrl) {
        LambdaQueryWrapper<TappMenuEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TappMenuEntity::getFmenuurl, menuUrl);
        return baseMapper.selectOne(queryWrapper);
    }
}